package cn.jee.dao;

import cn.jee.domain.Stu;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;
@Mapper
//注释+sql语句实现数据库操作
public interface StuMapper {
  @Cacheable("stu::all")
  @Select("select * from stu")
  List<Stu> find(); //List<Map>

  @Select("select * from stu where id=#{id}")
  Stu findById(long id);

  @CacheEvict(value="stu",allEntries = true)
  @Insert("insert into stu(username) values(#{username})")
  int add(Stu stu);

  @Insert("insert into stu(username) values(#{username})")
  //用keyProperty，自动产生的值放在哪个变量？
  //keyColumn指定哪一列是自动产生的
  @Options(useGeneratedKeys = true,keyProperty = "id")
  int add2(Stu stu);
  @Select("select count(*) from stu where username=#{username} and pass=#{pass}")
  int checkLogin(String username,String pass);
}
